package logic

import (
	"context"
	"useryk/model/mysql"

	"useryk/userrpc/internal/svc"
	"useryk/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CategorieListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCategorieListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CategorieListLogic {
	return &CategorieListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CategorieListLogic) CategorieList(in *userrpc.CategorieListRequest) (*userrpc.CategorieListResponse, error) {
	// todo: add your logic here and delete this line

	var categorie []mysql.Categorie
	mysql.DB.Find(&categorie)
	var lists []*userrpc.CategorieList
	for _, m := range categorie {
		list := userrpc.CategorieList{
			Categorieid:    int64(m.ID),
			Categoriename:  m.Categoriename,
			Categorieimage: m.Categorieimage,
			Keyword:        m.Keyword,
			Describe:       m.Describe,
			Userid:         m.Userid,
		}
		lists = append(lists, &list)
	}

	return &userrpc.CategorieListResponse{
		List: lists,
	}, nil
}
